package com.chengjj.kings.config.datasource;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.chengjj.kings.core.datascope.DataScopeInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author: 成俊杰
 * @CreateDate: 2019/3/12
 * @Version: 1.0
 * @Description: 单数据源配置
 */
@Configuration
@ConditionalOnProperty(prefix = "kings.muti-datasource", name = "open", havingValue = "false", matchIfMissing = true)
@EnableTransactionManagement
@MapperScan(basePackages = {"com.chengjj.kings.modular.*.mapper"})
public class SingleDataSourceConfig {
    /**
     * 自定义数据范围mybatis插件
     *
     * @return
     */
    @Bean
    public DataScopeInterceptor dataScopeInterceptor() {
        return new DataScopeInterceptor();
    }

    /**
     * 乐观锁mybatis插件
     *
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }
}
